/*
 *
 *  *  Copyright (c), utrix (idea110@163.com).
 *  *  <p>
 *  *  Licensed under the GNU Lesser General Public License 3.0 (the "License");
 *  *  you may not use this file except in compliance with the License.
 *  *  You may obtain a copy of the License at
 *  *  <p>
 *  * https://www.gnu.org/licenses/lgpl.html
 *  *  <p>
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

package priv.utrix.micro.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import priv.utrix.micro.constant.AuthConstants;
import priv.utrix.micro.converter.CustomAccessTokenConverter;
import priv.utrix.micro.converter.CustomJwtTokenConverter;

/**
 * token配置类
 *
 * @author utrix
 * @since 2020/9/28 21:50
 */
@Configuration
public class TokenConfig {

    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        // 自定义增强JWT转换器
        JwtAccessTokenConverter converter = new CustomJwtTokenConverter();
        converter.setSigningKey(AuthConstants.CLIENT_SIGNING_KEY);
        // 在资源服务器中配置类ResourceServerConfig中注入自定义token转换器
        converter.setAccessTokenConverter(new CustomAccessTokenConverter());
        return converter;
    }

}
